package com.test.tiles.controller.mypage;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.servlet.ModelAndView;

import com.test.tiles.model.vo.TestVo;
import com.test.tiles.model.vo.UserVo;
import com.test.tiles.model.vo.bbs.Bbs;
import com.test.tiles.service.LoginService;
import com.test.tiles.util.FileUpload;
import com.test.tiles.util.ParamUtil;
import com.test.tiles.util.SessionUtil;

/**
 * Handles requests for the application home page.
 */
@Controller
public class MypageController {
	
	private static final Logger logger = LoggerFactory.getLogger(MypageController.class);
	
	@Autowired
	private LoginService loginService;
	@Autowired
	private SessionUtil sessionUtil;
	
	
	//마이페이지
	
	@RequestMapping(value = "/mypage/index", method = RequestMethod.GET)
	public String index(Locale locale, Model model) {
		UserVo user = sessionUtil.getUser();
		if(!user.isLogin()){
			return "redirect:/login";
		}
		model.addAttribute("user", user);
		return "mypage/mypage";
	}
	
	@RequestMapping(value = "/mypage/orderList", method = RequestMethod.GET)
	public String orderList(Locale locale, Model model) {
		return "mypage/orderList";
	}
	
	@RequestMapping(value = "/mypage/couponList", method = RequestMethod.GET)
	public String couponList(Locale locale, Model model) {
		return "mypage/couponList";
	}
	@RequestMapping(value = "/mypage/reserveList", method = RequestMethod.GET)
	public String reserveList(Locale locale, Model model) {
		return "mypage/reserveList";
	}
	
	@RequestMapping(value = "/mypage/todayViewList", method = RequestMethod.GET)
	public String todayViewList(Locale locale, Model model) {
		return "mypage/todayViewList";
	}
	
	@RequestMapping(value = "/mypage/wishList", method = RequestMethod.GET)
	public String wishList(Locale locale, Model model) {
		return "mypage/wishList";
	}
	
	@RequestMapping(value = "/mypage/admin_index", method = RequestMethod.GET)
	public String admin_index(Locale locale, Model model) {
		UserVo user = sessionUtil.getUser();
		if(!user.isLogin()){
			return "redirect:/login";
		}
		TestVo productList = null;
		try{
			productList = loginService.selectProduct(new TestVo());
		}catch(Exception e){
			e.printStackTrace();
		}
		model.addAttribute("user", user);
		model.addAttribute("productList", productList );
		return "mypage/admin_index";
	}
	
}
